const CryptoJS = require("crypto-js");
exports.uuid = function () {
  var guid = "a";
  for (var i = 1; i <= 31; i++) {
    var n = Math.floor(Math.random() * 16).toString(16);
    guid += n;
    if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) {
      guid += "";
    }
  }
  guid += "";
  return guid;
}


//解密
function decrypt(text) {
  var decrypt = CryptoJS.TripleDES.decrypt(text, base64, {
    //iv: CryptoJS.enc.Utf8.parse('01234567'),
    //mode: CryptoJS.mode.CBC,
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  }
  );
  //解析数据后转为UTF-8
  var parseData = decrypt.toString(CryptoJS.enc.Utf8);
  return parseData;
  // document.getElementById("decrypt").innerText=parseData;
}

//秘钥key
var key = "9A6BF08E04244A2496A1972F";
//key不足24位自动以0(最小位数是0)补齐,如果多余24位,则截取前24位,后面多余则舍弃掉
var base64 = CryptoJS.enc.Utf8.parse(key)
console.log("base64", base64)
//加密使用的是3DES中的ECB,解密对应的使用ECB
function encrypt(text) {
  var encrypt = CryptoJS.TripleDES.encrypt(text, base64, {
    //iv: CryptoJS.enc.Utf8.parse('01234567'),//iv偏移量
    //mode: CryptoJS.mode.CBC,  //CBC模式
    mode: CryptoJS.mode.ECB,  //ECB模式
    padding: CryptoJS.pad.Pkcs7//padding处理
  }
  );

  var encryptData = encrypt.toString();//加密完成后，转换成字符串
  // console.log("encryptData",encrypt.ciphertext.toString().toUpperCase())
  return encrypt.ciphertext.toString().toUpperCase();
}
//7be08d73a7c9ac165b6d8f7942930394
console.log(encrypt('[{"bank_card_no":"6217560500021982595","bank_account":"22","id_card":"3622011544018"}]'));

// console.log(encrypt('[{"bank_card_no":"6217001760003532258"}]'));



// console.log(decrypt('lCQmxZG9js0bp2ydvEpTRqUTH17ZTgHQfCHH/586p0/6H2C6IJmFScbZBoa9A4e5GOFWBw224Qn8381iXb+yS+YJdivvErp0KIKGLNV9qc/m/IFlvD9ZxOUQkv2heImKk8DtbOTNRBE='))